package cn.com.generaldata.os.service.impl;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.annotation.InjectName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.com.generaldata.jsme_indicator_system.entity.ReportNz;
import cn.com.generaldata.jsme_indicator_system.entity.TransferReport;
import cn.com.generaldata.jsme_indicator_system.util.Constants;
import cn.com.generaldata.os.pojo.Report;

import com.google.common.collect.Lists;

@Component
@InjectName
public class SendReportService
{

	@Value("${gjme.type.ids}")
	private String typeIds;
	@Autowired
	CommonXmlReport xmlReportService;
	@Autowired
	CommonJsonReport jsonReportService;
	@Autowired
	private Dao indicatorSystemDao;

	public SendReportService()
	{
	}

	public synchronized void applyFishShow(Report report, HibernateInterceptor.InterceptorEvent event)
	{
		List<TransferReport> list = indicatorSystemDao.query(TransferReport.class, Cnd.where("enable", "=", Constants.YES));
		String reportIds[] = typeIds.split(",");
		List<String> reportList = Lists.newArrayList(reportIds);
		for(TransferReport tr:list){
			reportList.add(tr.getReportTypeId());
		}
		if (reportList.contains(report.getReportTypeId()))
		{
			System.out.println((new StringBuilder("---------调用直报接口----调用接口-------")).append(report.getId()).toString());
			ReportNz reportNz = (ReportNz)indicatorSystemDao.fetch(ReportNz.class, report.getId());
			jsonReportService.createJsonReport(reportNz, event);
		}
	}
}